import request from '@/utils/request'

/**
 * 创建文件夹
 * @param data
 * @returns {AxiosPromise}
 */
export function createFolder(data) {
    return request({
        url: '/resource/create',
        method: 'post',
        data: data
    })
}


/**
 * 修改文件名
 * @param data
 * @returns {AxiosPromise}
 */
export function updateFolder(data){
    return request({
        url: '/resource/update',
        method: 'post',
        data: data
    })
}

/**
 * 获取文件列表
 * @param id
 * @returns {AxiosPromise}
 */
export function getFolder(id) {
    return request({
        url: '/resource/getFolder/' + id,
        method: 'get'
    })
}

/**
 * 移动文件夹
 * @param id
 * @param beforeId
 * @returns {AxiosPromise}
 */
export function removeFolder(id,beforeId){
    return request({
        url: '/resource/removeFolder',
        method: 'post',
        params:{
            'id': id, // 被移动文件id
            'beforeId': beforeId  // 目标文件id
        }
    })
}

/**
 * 返回文件预览信息
 * @param id
 * @returns {AxiosPromise}
 */
export function getView(id){
    return request({
        url: '/resource/getprview',
        method: 'get',
        params: {id}
    })
}
// 文件树状结构
export function getTree(){
    return request({
        url: '/resource/folderList',
        method: 'get',
    })
}
/**
 * 文件上传
 * @param data
 * @returns {AxiosPromise}
 */
export function uploadFile(data){
    return request({
        url: '/resource/uploadFile?pId=' + $store.state.file.resource[this.$store.state.file.resource.length - 1].id,
        method: 'post',
        data: data
    })
}

// 文件夹下载
export function download(path,id){
    return request({
        url: '/resource/download',
        method: 'get',
        params:{
            folderPath: path,
            id: id
        }
    })
}

// 单个文件下载
export function downloadOne(path,fileUrl){
    return request({
        url: '/resource/downloadOne',
        method: 'get',
        params: {
            path: path,
            fileUrl: fileUrl
        }
    })
}
// 资源库移动至备份盘
export function removeFolderTobfp(id){
    return request({
        url: '/resource/removeFolderTobfp',
        method: 'post',
        params:{
            id: id
        }
    })
}

// 资源库移动至回收站
export function removeFolderTohsz(id){
    return request({
        url: '/resource/removeFolderTohsz',
        method: 'post',
        params:{
            id: id,
        }
    })
}

// 收藏
export function collect(data){
    return request({
        url: '/resource/collect',
        method: 'post',
        data: data
    })
}

// 移动到密码箱
export function removetolock(data){
    return request({
        url: '/box/removetor',
        method: 'post',
        data: data
    })
}
